Initial import of Blink MediaSource tests. 
diff --git a/media-source/mediasource-seek-during-pending-seek.html b/media-source/mediasource-seek-during-pending-seek.html new file mode 100644 index 0000000..94fe75b --- /dev/null +++ b/media-source/mediasource-seek-during-pending-seek.html 
@@ -0,0 +1,143 @@ +<!DOCTYPE html> +<html> + <head> + <script src="../resources/testharness.js"></script> + <script src="../resources/testharnessreport.js"></script> + <script src="mediasource-util.js"></script> + <link rel='stylesheet' href='../resources/testharness.css'> + </head> + <body> + <div id="log"></div> + <script> + + mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData) + { + mediaElement.play(); + + var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init); + var firstSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.media[0]); + var secondSegmentInfo = segmentInfo.media[2]; + var secondSegment = MediaSourceUtil.extractSegmentData(mediaData, secondSegmentInfo); + + // Append the initialization segment to trigger a transition to HAVE_METADATA. + test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer'); + test.expectEvent(mediaElement, 'loadedmetadata', 'Reached HAVE_METADATA'); + sourceBuffer.appendBuffer(initSegment); + + test.waitForExpectedEvents(function() + { + assert_false(mediaElement.seeking, 'mediaElement is not seeking'); + assert_equals(mediaElement.readyState, mediaElement.HAVE_METADATA, 'Still in HAVE_METADATA'); + + // Seek to a new position before letting the initial seek to 0 completes. + test.expectEvent(mediaElement, 'seeking', 'mediaElement'); + mediaElement.currentTime = secondSegmentInfo.timecode; + assert_true(mediaElement.seeking, 'mediaElement is seeking'); + + // Append media data for time 0. + test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer'); + sourceBuffer.appendBuffer(firstSegment); + }); + + test.waitForExpectedEvents(function() + { + // Verify that the media data didn't trigger a 'seeking' event or a transition beyond HAVE_METADATA. + assert_true(mediaElement.seeking, 'mediaElement is still seeking'); + assert_equals(mediaElement.readyState, mediaElement.HAVE_METADATA, 'Still in HAVE_METADATA'); + + // Append media data for the current position. + test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer'); + test.expectEvent(mediaElement, 'seeked', 'mediaElement finished seek'); + test.expectEvent(mediaElement, 'playing', 'mediaElement playing'); + sourceBuffer.appendBuffer(secondSegment); + }); + + test.waitForExpectedEvents(function() + { + test.expectEvent(mediaSource, 'sourceended', 'mediaSource ended'); + mediaSource.endOfStream(); + }); + + test.waitForExpectedEvents(function() + { + assert_greater_than(mediaElement.readyState, mediaElement.HAVE_CURRENT_DATA, 'Greater than HAVE_CURRENT_DATA'); + test.done(); + }); + + }, 'Test seeking to a new location before transitioning beyond HAVE_METADATA.', {timeout: 10000} ); + + mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData) + { + mediaElement.play(); + + var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init); + var firstSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.media[0]); + var secondSegmentInfo = segmentInfo.media[2]; + var secondSegment = MediaSourceUtil.extractSegmentData(mediaData, secondSegmentInfo); + var thirdSegmentInfo = segmentInfo.media[4]; + var thirdSegment = MediaSourceUtil.extractSegmentData(mediaData, thirdSegmentInfo); + + // Append the initialization segment to trigger a transition to HAVE_METADATA. + test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer'); + test.expectEvent(mediaElement, 'loadedmetadata', 'Reached HAVE_METADATA'); + sourceBuffer.appendBuffer(initSegment); + + test.waitForExpectedEvents(function() + { + test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer'); + test.expectEvent(mediaElement, 'playing', 'mediaElement playing'); + sourceBuffer.appendBuffer(firstSegment); + }); + + test.waitForExpectedEvents(function() + { + assert_greater_than(mediaElement.readyState, mediaElement.HAVE_CURRENT_DATA, 'Greater than HAVE_CURRENT_DATA'); + + // Seek to a new position. + test.expectEvent(mediaElement, 'seeking', 'mediaElement'); + mediaElement.currentTime = secondSegmentInfo.timecode; + assert_true(mediaElement.seeking, 'mediaElement is seeking'); + + }); + + test.waitForExpectedEvents(function() + { + assert_true(mediaElement.seeking, 'mediaElement is still seeking'); + + // Seek to a second position while the first seek is still pending. + test.expectEvent(mediaElement, 'seeking', 'mediaElement'); + mediaElement.currentTime = thirdSegmentInfo.timecode; + assert_true(mediaElement.seeking, 'mediaElement is seeking'); + + // Append media data for the first seek position. + test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer'); + sourceBuffer.appendBuffer(secondSegment); + }); + + test.waitForExpectedEvents(function() + { + assert_true(mediaElement.seeking, 'mediaElement is still seeking'); + + // Append media data for the second seek position. + test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer'); + test.expectEvent(mediaElement, 'seeked', 'mediaElement finished seek'); + sourceBuffer.appendBuffer(thirdSegment); + }); + + test.waitForExpectedEvents(function() + { + assert_false(mediaElement.seeking, 'mediaElement is no longer seeking'); + + test.expectEvent(mediaSource, 'sourceended', 'mediaSource ended'); + mediaSource.endOfStream(); + }); + + test.waitForExpectedEvents(function() + { + assert_greater_than(mediaElement.readyState, mediaElement.HAVE_CURRENT_DATA, 'Greater than HAVE_CURRENT_DATA'); + test.done(); + }); + }, 'Test seeking to a new location during a pending seek.', {timeout: 10000} ); + </script> + </body> +</html>